using Microsoft.AspNetCore.Mvc;
using ZR.Admin.WebApi.Filters;
using ZR.Model.Dto.Business.ProductionControl;
using ZR.Model.Models.ProductionControl;
using ZR.Service.IService.ProductionControl;

//创建时间：2024-10-09
namespace ZR.Admin.WebApi.Controllers
{
    /// <summary>
    /// DB块故障组
    /// </summary>
    [Verify]
    [Route("formula/faultlargegroup")]
    [ApiExplorerSettings(GroupName = "business")]
    public class FaultLargeGroupController : BaseController
    {
        /// <summary>
        /// DB块故障组接口
        /// </summary>
        private readonly IFaultLargeGroupService _FaultLargeGroupService;

        public FaultLargeGroupController(IFaultLargeGroupService FaultLargeGroupService)
        {
            _FaultLargeGroupService = FaultLargeGroupService;
        }

        /// <summary>
        /// 查询DB块故障组列表
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        [HttpGet("list")]
        [ActionPermissionFilter(Permission = "formula:faultlargegroup:list")]
        public IActionResult QueryFaultLargeGroup([FromQuery] FaultLargeGroupQueryDto parm)
        {
            var response = _FaultLargeGroupService.GetList(parm);
            return SUCCESS(response);
        }

        /// <summary>
        /// 查询DB块故障组详情
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpGet("{Id}")]
        [ActionPermissionFilter(Permission = "formula:faultlargegroup:query")]
        public IActionResult GetFaultLargeGroup(int Id)
        {
            var response = _FaultLargeGroupService.GetInfo(Id);

            var info = response.Adapt<FaultLargeGroupDto>();
            return SUCCESS(info);
        }

        /// <summary>
        /// 添加DB块故障组
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        [ActionPermissionFilter(Permission = "formula:faultlargegroup:add")]
        [Log(Title = "DB块故障组", BusinessType = BusinessType.INSERT)]
        public IActionResult AddFaultLargeGroup([FromBody] FaultLargeGroupDto parm)
        {
            var modal = parm.Adapt<FaultLargeGroup>().ToCreate(HttpContext);

            var response = _FaultLargeGroupService.AddFaultLargeGroup(modal);

            return SUCCESS(response);
        }

        /// <summary>
        /// 更新DB块故障组
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        [ActionPermissionFilter(Permission = "formula:faultlargegroup:edit")]
        [Log(Title = "DB块故障组", BusinessType = BusinessType.UPDATE)]
        public IActionResult UpdateFaultLargeGroup([FromBody] FaultLargeGroupDto parm)
        {
            var modal = parm.Adapt<FaultLargeGroup>().ToUpdate(HttpContext);
            var response = _FaultLargeGroupService.UpdateFaultLargeGroup(modal);

            return ToResponse(response);
        }

        /// <summary>
        /// 删除DB块故障组
        /// </summary>
        /// <returns></returns>
        [HttpDelete("delete/{ids}")]
        [ActionPermissionFilter(Permission = "formula:faultlargegroup:delete")]
        [Log(Title = "DB块故障组", BusinessType = BusinessType.DELETE)]
        public IActionResult DeleteFaultLargeGroup([FromRoute] string ids)
        {
            var idArr = Tools.SplitAndConvert<int>(ids);

            return ToResponse(_FaultLargeGroupService.Delete(idArr));
        }
    }
}